
<template>
  <div class="AddOrUpdate_main add_container column_two tenantMenu_main main_container">
    <div style="padding:20px 0 0 40px">订单完结后不可再次启用</div>

    <div class="main_main">
      <div
        ref="table_container"
        class="table_container"
      >
        <el-table
          ref="table"
          :data="noChooseList"
          stripe
          border
          row-key="id"
          style="width: 99.9%;"
          :height="tableHeight"
          :cell-class-name="cellClassName"
          :row-class-name="rowClassName"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column type="selection" align="center" />
          <el-table-column label="物料编码" width="180" prop="materialCode" />
          <el-table-column label="物料名称" width="180" prop="materialName" />
          <el-table-column label="规格型号" width="180" prop="materialModel" />
          <el-table-column label="物料单位" width="180" prop="materialUnitLabel" />
          <el-table-column label="需求数量" width="180" prop="needNumber" />
          <el-table-column label="外协数量" width="180" prop="outsourceNumber" />
          <el-table-column label="含税单价" width="180" prop="taxPrice" />
          <el-table-column label="税率%" width="180" prop="taxRateCode" />
          <el-table-column label="含税总金额" width="140" prop="totalTaxPrice" />
          <el-table-column label="外协交期" width="240" prop="outsourceDeliveryTime" />
          <el-table-column label="备注" width="180" prop="remark" />
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <el-button type="cancel" @click.stop="cancel">取消</el-button>
      <el-button @click.stop="onSubmit">确定</el-button>
    </div>
  </div>
</template>

<script>
import {
  addOrUpdate,
  getInfo
} from '@/api/outsourceManage/outsourceOrder'
export default {
  name: 'AddOrUpdate',
  props: {
    layerid: {},
    id: {},
    defaultValue: {},
    isAdd: {}
  },
  data() {
    return {
      pageData: {
        pageNum: 1,
        pageSize: 9999,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      formData: {},
      noChooseList: [],
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      listData: [],
      taxRateCodeList: [],
      tableHeight: '0',
      templateSelection: '',
      tableData: [],
      mainId: 'id'
    }
  },
  created() {
    this.getInfo()
  },
  mounted() {
    this.$nextTick(() => {
      console.log(this.$refs)
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    handleSelectionChange(e) {
      console.log(e)
    },
    cellClassName(data) {
      if (data.column.property == 'operate') {
        if (data.rowIndex % 2 == 0) {
          // 单数行
          return 'fixed one'
        } else {
          // 双数行
          return 'fixed two'
        }
      }
    },
    rowClassName({ row, rowIndex }) {
      if (rowIndex == this.tableData.length - 1) {
        return 'addRow'
      }
    },
    getInfo() {
      getInfo(this.id).then((res) => {
        this.formData = res.data
        this.listData = res.data.detailList
        this.listData.forEach(ele => {
          if (this.formData.status == '1') {
            this.noChooseList.push(ele)
          }
        })
      })
    },
    // 提交
    onSubmit() {
      const list = this.listData.filter(item => {
        return !this.selectionsAll.includes(item)
      })
      this.selectionsAll.forEach(ele => {
        ele.status = '2'
      })
      list.push(...this.selectionsAll)
      this.formData.data = this.$deepClone(list)
      addOrUpdate(this.formData).then((res) => {
        this.$message({
          message: res.msg,
          type: 'success'
        })
        this.$layer.close(this.layerid) // 关闭弹框
        this.$parent.getList() // 调用父组件的刷新方法
      })
    },
    cancel() {
      this.$layer.close(this.layerid) // 关闭弹框
    }

  }
}
</script>

<style lang="less" scoped>
.form_padding{
  padding: 0 !important;
}
.title {
  padding-left: 10px;
  padding-bottom: 20px;
  font-size: 24px;
  width: 100%;
}
.numberComponents {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}
/deep/ .el-input-number.is-controls-right .el-input-number__increase {
  height: 15px;
}
.el-icon-remove {
  font-size: 25px;
  color: red;
  height: 100%;
  width: 100%;
  border: 0px;
  background-color: transparent;
}
/deep/ .el-form-item__content {
  margin-left: 0 !important;
}
/deep/ .el-form-item__label {
  text-align: right;
}
.expand_radio {
  /deep/ .el-form-item__content {
    text-align: left;
  }
}
.expand_container {
  .el-form-item {
    margin-bottom: 10px;
  }
  .expand_file {
    margin-bottom: 0px;
  }

  /deep/ .el-form-item__label {
    width: 130px !important;
  }
  /deep/ .el-form-item__content {
    width: 710px !important;
  }
}
.main_main {
  margin: 0 !important;
  padding: 0 !important;
  .form_padding {
    /deep/ .el-form-item {
      margin-right: 0px;
    }
    /deep/ .el-form-item__label {
      width: 120px !important;
    }
    /deep/ .el-form-item__content {
      width: 270px;
    }
    .remark {
      /deep/ .el-form-item__content {
        width: 690px !important;
        height: 60px;
        overflow-y: auto;
      }
    }
  }
}
/deep/ .el-table th.el-table__cell > .cell {
  position: unset;
}
.order_header{
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  .info_button{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
  }
}
</style>
